//Manage Member

$(function ()
{
	adminShowScitechInformation();
});
	function allStdProfile()  
		{
			$.get('page/admin-login-studentprofile.php',function(data)
				{
					showStudentProfile();
					$('#adminInformation').html(data);
				});
		}


	function adminShowInformation()  
		{	
			
			$.get('page/admin-addinformation.php',function(data)
				{	
					
					getSubjectName();
					$("#datepicker" ).datepicker();
					$('#adminInformation').html(data);
					$('#tchuser').hide;

				});
		}
			function getSubjectName() 
		{
			$.getJSON('function/json-subject.php',function(data) 
			{
				$('#subject').html('<option></option>');
				$.each(data,function(key, val) 
				{
					$('#subject').html(
					$('#subject').html()
					+ '<option id="'+val['sub_id']+'">'+val['subject_name']+'</option>'
					);
				});
			});
		}

	function addInformationAdmin()
		{	

			if($('#title').val()=='')
			{
				alert("Please insert Information's title");
			}
			else if($('#subject').val()=='')
			{
				alert("Please insert Information's subject");
			}
			else if($('#startDate').val()=='')
			{
				alert("Please insert start date");
			}
			else if($('#endDate').val()=='')
			{
				alert("Please insert end date");
			}
			else if($('#detail').val()=='')
			{
				alert("Please insert Information's detail");
			}
			else if($('#faculty').val()=='')
			{
				alert("Please insert Information's faculty");
			}
			else{
			$.post('function/response-information-admin.php',{
				'inf_title' : $('#title').val(),
				'inf_date_start' : $('#startDate').val(),
				'inf_date_end' : $('#endDate').val(),
				'inf_subject' : $('#subject').val(),
				'inf_faculty' : $('#faculty').val(),
				'inf_type' : $('#typeinf').val(),
				'inf_detail' : $('#detail').val()},
				function(data)//·Ó¡ÒÃÃÕº¢éÍÁÙÅÁÒ¨Ò¡ response.php â´Â·Ó¡ÒÃÃÑº¢éÍÁÙÅµÒÁ·Õèä´é¡ÓË¹´äÇé
			{	
				alert("Add information successful");});
				afterRegister();
			}
		}
	function allTchProfile()  
		{
			$.get('page/admin-login-teacherprofile.php',function(data)
				{
					showTeacherProfile();
					$('#adminInformation').html(data);
				});
		}
		
		function adminMngInformation()
		{
				$.get('page/admin-login-mnginformation.php',function(data)
				{
					showAllInformation();
					$('#adminInformation').html(data);
				});
		}
		
		function showAllInformation()
		{
			$('#informationMain').html('Loading...');
				$.getJSON('function/json-information.php',function(data)
			{
			$('#informationMain').html('');
			$.each(data,function(key,val){
			$('#informationMain').html(
			$('#informationMain').html()
			+'<table>'
			+'<div style="display:none">'+val['inf_id']+'</div>'
			+'<tr><td width=180>'
			+'<font color="white" size=3>'
			+val['inf_type']
			+'</font></td>'
			+'<td width="200">'
			+'<font color="white" size=3>'
			+val['inf_title']
			+'</font>'
			+'<td width=250>'
			+'<font color="white" size=3>'
			+val['inf_subject']
			+'</font>'
			+'</td><td width="290">'
			+'<font color="white" size=3>'
			+val['inf_faculty']
			+'</font>'
			+'</td><td><font color="white" size=3 style="cursor:pointer;" onclick="adminClick('+val['inf_id']+');" >More...</font>'
			+'</td></tr></table>'
			+'<img src="Picture-project/PNGfile/Text-line.png" width=1000>'
			);
			});
			});
		}

		function adminClick(inf_id)
		{
			$.get('page/admin-login-show-information-detail.php',function(data)
				{	
					
					moreInformation(inf_id)
					$('#adminInformation').html(data);

				});
		}


		function adminShowScitechInformation() 
			{
				$.get('page/show-scitech.php',function(data)
					{
						adminScitechInformation();
						$('#adminInformation').html(data);
					});
			}
		function adminScitechInformation() 
			{
					
					$('#informationMain').html('Loading...');
					$.getJSON('function/json-scitech.php',function(data)
					{
					$('#informationMain').html('');
					$.each(data,function(key,val){
					$('#informationMain').html(
					$('#informationMain').html()+
					'<div id="data'+val['id']+'">'
					+'<table><tr>'
					+'<div style="display:none>"'+val['inf_id']+'</div>'
					+'<td width=150>'
					+'<font color="white" size=3>'
					+val['inf_type']
					+'</font>'
					+'</td><td width="300">'
					+'<font color="white" size=3>'
					+val['inf_subject']
					+'</font>'
					+'</td><td width="330">'
					+'<font color="white" size=3>'
					+val['inf_title']
					+'</font></div>'
					+'</td><td width=150>'
					+'<font color="white" size=3>'
					+val['inf_date_end']
					+'</font></div>'
					+'</td><td>'
					+'<font color="white" size=3 style="cursor:pointer;" onclick="adminClickScitech('+val['inf_id']+');" >More...</font>'
					+'</td></tr></table>'
					+'<img src="Picture-project/PNGfile/Text-line.png" width=1000>'
					);
					});
					});
			}
	function adminShowSeInformation()  
		{
			$.get('page/show-software.php',function(data)
				{
					adminSoftwareInformation();
					$('#adminInformation').html(data);
				});
		}
		function adminSoftwareInformation() 

			{
				$('#informationMain').html('Loading...');
					$.getJSON('function/json-software-subject.php',function(data)
				{
				$('#informationMain').html('');
				$.each(data,function(key,val){
				$('#informationMain').html(
				$('#informationMain').html()+
				'<div id="data'+val['id']+'">'
					+'<table><tr>'
					+'<div style="display:none>"'+val['inf_id']+'</div>'
					+'<td width=150>'
					+'<font color="white" size=3>'
					+val['inf_type']
					+'</font>'
					+'</td><td width="300">'
					+'<font color="white" size=3>'
					+val['inf_subject']
					+'</font>'
					+'</td><td width="330">'
					+'<font color="white" size=3>'
					+val['inf_title']
					+'</font></div>'
					+'</td><td width=150>'
					+'<font color="white" size=3>'
					+val['inf_date_end']
					+'</font></div>'
					+'</td><td>'
					+'<font color="white" size=3 style="cursor:pointer;" onclick="adminClickSe('+val['inf_id']+');" >More...</font>'
					+'</td></tr></table>'
					+'<img src="Picture-project/PNGfile/Text-line.png" width=1000>'
					);
					});
					});
			}

	function adminShowItInformation()  
		{
			$.get('page/show-it.php',function(data)
				{
					adminItInformation();
					$('#adminInformation').html(data);
				});
		}
		function adminItInformation() 
			{
				$('#informationMain').html('Loading...');
					$.getJSON('function/json-it-subject.php',function(data)
				{
				$('#informationMain').html('');
				$.each(data,function(key,val){
				$('#informationMain').html(
				$('#informationMain').html()+
				'<div id="data'+val['id']+'">'
					+'<table><tr>'
					+'<div style="display:none>"'+val['inf_id']+'</div>'
					+'<td width=150>'
					+'<font color="white" size=3>'
					+val['inf_type']
					+'</font>'
					+'</td><td width="300">'
					+'<font color="white" size=3>'
					+val['inf_subject']
					+'</font>'
					+'</td><td width="330">'
					+'<font color="white" size=3>'
					+val['inf_title']
					+'</font></div>'
					+'</td><td width=150>'
					+'<font color="white" size=3>'
					+val['inf_date_end']
					+'</font></div>'
					+'</td><td>'
					+'<font color="white" size=3 style="cursor:pointer;" onclick="adminClickIt('+val['inf_id']+');" >More...</font>'
					+'</td></tr></table>'
					+'<img src="Picture-project/PNGfile/Text-line.png" width=1000>'
					);
					});
					});
			}
	function adminShowEcomInformation()  
		{
			$.get('page/show-ecom.php',function(data)
				{
					adminEcomInformation();
					$('#adminInformation').html(data);
				});
			}
		function adminEcomInformation() 
		{
			$('#informationMain').html('Loading...');
					$.getJSON('function/json-ecom-subject.php',function(data)
				{
				$('#informationMain').html('');
				$.each(data,function(key,val){
				$('#informationMain').html(
				$('#informationMain').html()+
				'<div id="data'+val['id']+'">'
					+'<table><tr>'
					+'<div style="display:none>"'+val['inf_id']+'</div>'
					+'<td width=150>'
					+'<font color="white" size=3>'
					+val['inf_type']
					+'</font>'
					+'</td><td width="300">'
					+'<font color="white" size=3>'
					+val['inf_subject']
					+'</font>'
					+'</td><td width="330">'
					+'<font color="white" size=3>'
					+val['inf_title']
					+'</font></div>'
					+'</td><td width=150>'
					+'<font color="white" size=3>'
					+val['inf_date_end']
					+'</font></div>'
					+'</td><td>'
					+'<font color="white" size=3 style="cursor:pointer;" onclick="adminClickEcom('+val['inf_id']+');" >More...</font>'
					+'</td></tr></table>'
					+'<img src="Picture-project/PNGfile/Text-line.png" width=1000>'
					);
					});
					});
		}
	function adminShowBcomInformation()  
		{
			$.get('page/show-bcom.php',function(data)
				{
					adminBcomInformation();
					$('#adminInformation').html(data);
				});
		}
		function adminBcomInformation() 
		{
			$('#informationMain').html('Loading...');
					$.getJSON('function/json-bcom-subject.php',function(data)
				{
				$('#informationMain').html('');
				$.each(data,function(key,val){
				$('#informationMain').html(
				$('#informationMain').html()+
				'<div id="data'+val['id']+'">'
					+'<table><tr>'
					+'<div style="display:none>"'+val['inf_id']+'</div>'
					+'<td width=150>'
					+'<font color="white" size=3>'
					+val['inf_type']
					+'</font>'
					+'</td><td width="300">'
					+'<font color="white" size=3>'
					+val['inf_subject']
					+'</font>'
					+'</td><td width="330">'
					+'<font color="white" size=3>'
					+val['inf_title']
					+'</font></div>'
					+'</td><td width=150>'
					+'<font color="white" size=3>'
					+val['inf_date_end']
					+'</font></div>'
					+'</td><td>'
					+'<font color="white" size=3 style="cursor:pointer;" onclick="adminClickBcom('+val['inf_id']+');" >More...</font>'
					+'</td></tr></table>'
					+'<img src="Picture-project/PNGfile/Text-line.png" width=1000>'
					);
					});
					});
		}

		function adminClickScitech(inf_id)
		{
			$.get('page/admin-login-show-full-scitech.php',function(data)
				{	
					
					adminShowInfDetail(inf_id);
					$('#adminInformation').html(data);

				});
		}
		function adminClickSe(inf_id)
		{
			$.get('page/admin-login-show-full-se.php',function(data)
				{	
					
					adminShowInfDetail(inf_id);
					$('#adminInformation').html(data);

				});
		}
		function adminClickIt(inf_id)
		{
			$.get('page/admin-login-show-full-it.php',function(data)
				{	
					
					adminShowInfDetail(inf_id);
					$('#adminInformation').html(data);

				});
		}
		function adminClickBcom(inf_id)
		{
			$.get('page/admin-login-show-full-bcom.php',function(data)
				{	
					
					adminShowInfDetail(inf_id);
					$('#adminInformation').html(data);

				});
		}
		function adminClickEcom(inf_id)
		{
			$.get('page/admin-login-show-full-ecom.php',function(data)
				{	
					
					adminShowInfDetail(inf_id);
					$('#adminInformation').html(data);

				});
		}

		function adminShowInfDetail(inf_id)
		{		
			$('#informationMain').html('Loading...');
			$.getJSON('function/json-admin-show-full-information.php',{ "inf_id" : inf_id},function(data)
			{ 
		
			$('#informationMain').html('');
			$.each(data,function(key,val){
			$('#informationMain').html(
			$('#informationMain').html()
			+'<table>'
			+'<tr><td widht=1050 height=400>'
			
			+'<table>'
			+'<tr><td widht=370 height=400>'
			
			+'<table>'
			+'<div style="display:none">'+val['inf_id']+'</div>'
			+'<tr><td width=170><font color=white size=3> TYPE </font></td>'
			+'<td width=200><font color=white size=3>'+val['inf_type']+'</font></td></tr>'
			+'<tr><td height=15></td><td></td></tr>'
			+'<tr><td width=170><font color=white size=3> TITLE </font></td>'
			+'<td width=200><font color=white size=3><span id="value1'+val['inf_id']+'">'+val['inf_title']+'</span></font></td></tr>'
			+'<tr><td width=170><font color=white size=3> FACULTY </font></td>'
			+'<td width=200><font color=white size=3>'+val['inf_faculty']+'</font></td></tr>'
			+'<tr><td width=170><font color=white size=3> SUBJECT </font></td>'
			+'<td width=200><font color=white size=3>'+val['inf_subject']+'</font></td></tr>'
			+'<tr><td height=15></td><td></td></tr>'
			+'<tr><td width=170><font color=white size=3> START DATE </font></td>'
			+'<td width=200><font color=white size=3>'+val['inf_date_start']+'</font></td></tr>'
			+'<tr><td width=170><font color=white size=3> END DATE </font></td>'
			+'<td width=200><font color=white size=3><span id="value2'+val['inf_id']+'">'+val['inf_date_end']+'</span></font></td></tr>'
			+'<tr><td height=190>'
			+'</td><td>'
			+'</td></tr>'
			+'<tr><td>'
			+'</td></tr>'
			+'</table>'
			
			
			+'</td><td widht=630>'
			
			+'<table>'
			+'<tr><td><font color=white size=3> DETAIL </font></td></tr>'
			+'</table>'
			
			+'<div style="width: 630px; height: 350px; overflow-y: scroll; scrollbar-arrow-color:blue; scrollbar-face-color: #e7e7e7; scrollbar-3dlight-color: #a0a0a0; scrollbar-darkshadow-color:#888888">'
			+'<table>'
			+'<td ><font color=white size=3><span id="value3'+val['inf_id']+'">'+val['inf_detail']+'</span></font></td></tr>'
			+'</table>'
			+'</div>'
			
			+'</td></tr>' 
			+'</table>'
			

			
			
			);
			});
			});
		}


		
		function moreInformation(inf_id)
		{	
			$('#informationMain').html('Loading...');
			$.getJSON('function/response-sendidinf-admin.php',{ "inf_id" : inf_id},function(data)
			{ 
			$('#informationMain').html('');
			$.each(data,function(key,val){
			$('#informationMain').html(
			$('#informationMain').html()
			+'<table>'
			+'<tr><td widht=1050 height=400>'
			
			+'<table>'
			+'<tr><td widht=370 height=400>'
			
			+'<table>'
			+'<div style="display:none">'+val['inf_id']+'</div>'
			+'<tr><td width=170><font color=white size=3> USERS POST </font></td>'
			+'<td width=200><font color=white size=3>'+val['inf_user']+'</font></td></tr>'
			+'<tr><td width=170><font color=white size=3> TYPE </font></td>'
			+'<td width=200><font color=white size=3>'+val['inf_type']+'</font></td></tr>'
			+'<tr><td height=15></td><td></td></tr>'
			+'<tr><td width=170><font color=white size=3> TITLE </font></td>'
			+'<td width=200><font color=white size=3><span id="value1'+val['inf_id']+'">'+val['inf_title']+'</span></font></td></tr>'
			+'<tr><td width=170><font color=white size=3> FACULTY </font></td>'
			+'<td width=200><font color=white size=3>'+val['inf_faculty']+'</font></td></tr>'
			+'<tr><td width=170><font color=white size=3> SUBJECT </font></td>'
			+'<td width=200><font color=white size=3>'+val['inf_subject']+'</font></td></tr>'
			+'<tr><td height=15></td><td></td></tr>'
			+'<tr><td width=170><font color=white size=3> START DATE </font></td>'
			+'<td width=200><font color=white size=3>'+val['inf_date_start']+'</font></td></tr>'
			+'<tr><td width=170><font color=white size=3> END DATE </font></td>'
			+'<td width=200><font color=white size=3><span id="value2'+val['inf_id']+'">'+val['inf_date_end']+'</span></font></td></tr>'
			+'<tr><td height=140>'
			+'</td><td></td></tr>'
			+'</table>'
			+'<img id="editimg'+val['inf_id']+'" src="Picture-project/PNGfile/edit-icon.png" style="cursor:pointer;" onclick="editInformation('+val['inf_id']+');">'
			+'<img id="delimg'+val['sub_id']+'" src="Picture-project/PNGfile/del-icon.png" style="cursor:pointer;" onclick="delInformation('+val['inf_id']+');">'
			+'</td><td widht=630>'
			
			+'<table>'
			+'<tr><td><font color=white size=3> DETAIL </font></td></tr>'
			+'</table>'
			
			+'<div style="width: 630px; height: 350px; overflow-y: scroll; scrollbar-arrow-color:blue; scrollbar-face-color: #e7e7e7; scrollbar-3dlight-color: #a0a0a0; scrollbar-darkshadow-color:#888888">'
			+'<table>'
			+'<td ><font color=white size=3><span id="value3'+val['inf_id']+'">'+val['inf_detail']+'</span></font></td></tr>'
			+'</table>'
			+'</div>'
			
			+'</td></tr></table>'
			
			);
			});
			});
		}


		
		function editInformation(inf_id)
		{
			$('#editimg'+inf_id).hide();
$('#value1'+inf_id).html('<input id="txtvalue1'+inf_id+'" type="text" onkeydown = "updateInformation('+inf_id+',event);" value="'+$('#value1'+inf_id).html()+'">');
$('#value2'+inf_id).html('<input id="txtvalue2'+inf_id+'" type="text" onkeypress="return isNumberKey(event)" onkeydown = "updateInformation('+inf_id+',event);" value="'+$('#value2'+inf_id).html()+'">');
$('#value3'+inf_id).html('<textarea id="txtvalue3'+inf_id+'" type="text" onkeydown = "updateInformation('+inf_id+',event);" >'+$('#value3'+inf_id).html()+'</textarea>');
		}

		function updateInformation(inf_id,event)
		{
			if(event.keyCode==13)//เมื่อกด Enter 
			{
				if($('#txtvalue1'+inf_id+'').val()=='')
				{
				event.preventDefault();
				alert('Please insert informations title');
				}
				else if($('#txtvalue2'+inf_id).val()=='')
				{
				event.preventDefault();
				alert('Please insert informations end date');
				}
				else if($('#txtvalue3'+inf_id).val()=='')
				{
				event.preventDefault();
				alert('Please insert informations detail');
				}
				else if($('#txtvalue1'+inf_id).val()==(event.keyCode==32))
				{
				event.preventDefault();
				alert('Please insert informations title');
				}
				else if($('#txtvalue2'+inf_id).val()==(event.keyCode==32))
				{
				event.preventDefault();
				alert('Please insert informations end date');
				}
				else if($('#txtvalue3'+inf_id).val()==(event.keyCode==32))
				{
				event.preventDefault();
				alert('Please insert informations detail');
				}
				else
				{
					$('#editimg'+inf_id).show();
					$.post('function/update.php',
					{
						'inf_title' : $('#txtvalue1'+inf_id).val(), 'inf_date_end' : $('#txtvalue2'+inf_id).val() , 'inf_detail' : $('#txtvalue3'+inf_id).val(), 'inf_id' : inf_id
					},function(data)
					{
						$('#value1'+inf_id).html($('#txtvalue1'+inf_id).val());
						$('#value2'+inf_id).html($('#txtvalue2'+inf_id).val());
						$('#value3'+inf_id).html($('#txtvalue3'+inf_id).val());
						});
				}
				showAllInformation()
			}
		}

		function delInformation(inf_id)
		{
				if (confirm("Do you want to delete ?") )
					{
							$.post('function/delete.php',{'inf_id': inf_id} , function(data)//ใส่{'id':id} เข้าไปเพื่อรับ id จาก delete.php
						{
							adminMngInformation();
						});
					}
				else
					{
						showAllInformation();
					}
		}
		
		function pageForMoreInformation()
		{
			$.post('page/admin-login-showinformation.php',function(data)
				{
					$('#adminInformation').html(data);
					getInformation();
				});
		}
	
	function showStudentProfile() 
		{
			$('#informationMember').html('Loading...');
				$.getJSON('function/json-student.php',function(data)
			{
			$('#informationMember').html('');
			$.each(data,function(key,val){
			$('#informationMember').html(
			$('#informationMember').html()
			+'<table><tr>'
			+'<div style="display:none">'+val['student_id']+'</div>'
			+'<td width=150>'
			+'<font color="white" size=3>'
			+'<span id="value'+val['student_id']+'">'+val['student_firstname']+'</span>'
			+'</font></td>'
			+'<td width="150">'
			+'<font color="white" size=3>'
			+'<span id="value2'+val['student_id']+'">'+val['student_lastname']+'</span>'
			+'</font>'
			+'<td width=120>'
			+'<font color="white" size=3>'
			+'<span id="value3'+val['student_id']+'">'+val['student_ncuid']+'</span>'
			+'</font>'
			+'</td><td width="260">'
			+'<font color="white" size=3>'
			+'<span id="value4'+val['student_id']+'">'+val['student_email']+'</span>'
			+'</font></td>'
			+'<td width=140>'
			+'<font color="white" size=3>'
			+'<span id="value5'+val['student_id']+'">'+val['student_tel']+'</span>'
			+'</font></td>'
			+'<td width=100>'
			+'<font color="white" size=3>'
			+'<span id="value6'+val['student_id']+'">'+val['student_faculty']+'</span>'
			+'</font>'
			+'</td><td width=50> <img id="editimg'+val['student_id']+'" src="Picture-project/PNGfile/edit-icon.png" style="cursor:pointer;" onclick="editStudent('+val['student_id']+');">'
			+'<img id="delimg'+val['student_id']+'" src="Picture-project/PNGfile/del-icon.png" style="cursor:pointer;" onclick="delStudent('+val['student_id']+');">'
			+'</td></tr></table>'
			+'<img src="Picture-project/PNGfile/Text-line.png" width=1000>'
			);
			});
			});
		}
		
			function editStudent(student_id)
		{
$('#editimg'+student_id).hide();
$('#value'+student_id).html('<input id="txtvalue'+student_id+'" type="text" onkeypress="return isStringKey(event)" onkeydown = "updateStudent('+student_id+',event);" value="'+$('#value'+student_id).html()+'">');
$('#value2'+student_id).html('<input id="txtvalue2'+student_id+'" type="text" onkeypress="return isStringKey(event)" onkeydown = "updateStudent('+student_id+',event);" value="'+$('#value2'+student_id).html()+'">');
$('#value3'+student_id).html('<input id="txtvalue3'+student_id+'" type="text" onkeypress="return isNumberKey(event)" onkeydown = "updateStudent('+student_id+',event);" value="'+$('#value3'+student_id).html()+'">');
$('#value4'+student_id).html('<input id="txtvalue4'+student_id+'" type="text" onkeydown = "updateStudent('+student_id+',event);" value="'+$('#value4'+student_id).html()+'">');
$('#value5'+student_id).html('<input id="txtvalue5'+student_id+'" type="text" onkeypress="return isNumberKey(event)" onkeydown = "updateStudent('+student_id+',event);" value="'+$('#value5'+student_id).html()+'">');
$('#value6'+student_id).html('<input id="txtvalue6'+student_id+'" type="text" onkeypress="return isStringKey(event)" onkeydown = "updateStudent('+student_id+',event);" value="'+$('#value6'+student_id).html()+'">');		
		}

	function updateStudent(student_id,event)
		{
			if(event.keyCode==13)//เมื่อกด Enter 
			{
				if($('#txtvalue'+student_id+'').val()=='')
				{
				event.preventDefault();
				alert('Please insert students firstname');
				}
				else if($('#txtvalue2'+student_id).val()=='')
				{
				event.preventDefault();
				alert('Please insert students lastname');
				}
				else if($('#txtvalue3'+student_id).val()=='')
				{
				event.preventDefault();
				alert('Please insert students ncu id');
				}
				else if($('#txtvalue4'+student_id).val()=='')
				{
				event.preventDefault();
				alert('Please insert students email');
				}
				else if($('#txtvalue6'+student_id).val()=='')
				{
				event.preventDefault();
				alert('Please insert students faculty');
				}
				else if($('#txtvalue'+student_id).val()==(event.keyCode==32))
				{
				event.preventDefault();
				alert('Please insert students firstname');
				}
				else if($('#txtvalue2'+student_id).val()==(event.keyCode==32))
				{
				event.preventDefault();
				alert('Please insert students lastname');
				}
				else if($('#txtvalue3'+student_id).val()==(event.keyCode==32))
				{
				event.preventDefault();
				alert('Please insert students ncu id');
				}
				else if($('#txtvalue4'+student_id).val()==(event.keyCode==32))
				{
				event.preventDefault();
				alert('Please insert students email');
				}
				else if($('#txtvalue6'+student_id).val()==(event.keyCode==32))
				{
				event.preventDefault();
				alert('Please insert students faculty');
				}
				else
				{
					$('#editimg'+student_id).show();
					$.post('function/update.php',
					{
						'student_firstname' : $('#txtvalue'+student_id).val(), 'student_lastname' : $('#txtvalue2'+student_id).val() , 'student_ncuid' : $('#txtvalue3'+student_id).val(),'student_email' : $('#txtvalue4'+student_id).val(), 'student_tel' : $('#txtvalue5'+student_id).val(), 'student_faculty' : $('#txtvalue6'+student_id).val() , 'student_id' : student_id
					},function(data)
					{
						$('#value'+student_id).html($('#txtvalue'+student_id).val());
						$('#value2'+student_id).html($('#txtvalue2'+student_id).val());
						$('#value3'+student_id).html($('#txtvalue3'+student_id).val());
						$('#value4'+student_id).html($('#txtvalue4'+student_id).val());
						$('#value5'+student_id).html($('#txtvalue5'+student_id).val());
						$('#value6'+student_id).html($('#txtvalue6'+student_id).val());
					});
				}
				mngSubject();
			}
		}

	function showTeacherProfile() 
		{
			$('#informationMember').html('Loading...');
				$.getJSON('function/json-teacher.php',function(data)
			{
			$('#informationMember').html('');
			$.each(data,function(key,val){
			$('#informationMember').html(
			$('#informationMember').html()
			+'<table><tr>'
			+'<div style="display:none">'+val['teacher_id']+'</div>'
			+'<td width=150>'
			+'<font color="white" size=3>'
			+'<span id="value'+val['teacher_id']+'">'+val['teacher_firstname']+'</span>'
			+'</font></td>'
			+'<td width="150">'
			+'<font color="white" size=3>'
			+'<span id="value2'+val['teacher_id']+'">'+val['teacher_lastname']+'</span>'
			+'</font>'
			+'<td width=120>'
			+'<font color="white" size=3>'
			+'<span id="value3'+val['teacher_id']+'">'+val['teacher_ncuid']+'</span>'
			+'</font>'
			+'</td><td width="260">'
			+'<font color="white" size=3>'
			+'<span id="value4'+val['teacher_id']+'">'+val['teacher_email']+'</span>'
			+'</font></td>'
			+'<td width=140>'
			+'<font color="white" size=3>'
			+'<span id="value5'+val['teacher_id']+'">'+val['teacher_tel']+'</span>'
			+'</font></td>'
			+'<td width=100>'
			+'<font color="white" size=3>'
			+'<span id="value6'+val['teacher_id']+'">'+val['teacher_faculty']+'</span>'
			+'</font>'
			+'</td><td width=50> <img id="editimg'+val['teacher_id']+'" src="Picture-project/PNGfile/edit-icon.png" style="cursor:pointer;" onclick="editTeacher('+val['teacher_id']+');">'
			+'<img id="delimg'+val['teacher_id']+'" src="Picture-project/PNGfile/del-icon.png" style="cursor:pointer;" onclick="delTeacher('+val['teacher_id']+');">'
			+'</td></tr></table>'
			+'<img src="Picture-project/PNGfile/Text-line.png" width=1000>'
			);
			});
			});
		}
		
		function editTeacher(teacher_id)
		{
			$('#editimg'+teacher_id).hide();
			$('#value'+teacher_id).html('<input id="txtvalue'+teacher_id+'" onkeypress="return isStringKey(event)" type="text" onkeydown = "updateTeacher('+teacher_id+',event);" value="'+$('#value'+teacher_id).html()+'">');
			$('#value2'+teacher_id).html('<input id="txtvalue2'+teacher_id+'" onkeypress="return isStringKey(event)" type="text" onkeydown = "updateTeacher('+teacher_id+',event);" value="'+$('#value2'+teacher_id).html()+'">');
			$('#value3'+teacher_id).html('<input id="txtvalue3'+teacher_id+'" onkeypress="return isNumberKey(event)" type="text" onkeydown = "updateTeacher('+teacher_id+',event);" value="'+$('#value3'+teacher_id).html()+'">');
			$('#value4'+teacher_id).html('<input id="txtvalue4'+teacher_id+'" type="text" onkeydown = "updateTeacher('+teacher_id+',event);" value="'+$('#value4'+teacher_id).html()+'">');
			$('#value5'+teacher_id).html('<input id="txtvalue5'+teacher_id+'" onkeypress="return isNumberKey(event)" type="text" onkeydown = "updateTeacher('+teacher_id+',event);" value="'+$('#value5'+teacher_id).html()+'">');
			$('#value6'+teacher_id).html('<input id="txtvalue6'+teacher_id+'" onkeypress="return isStringKey(event)" type="text" onkeydown = "updateTeacher('+teacher_id+',event);" value="'+$('#value6'+teacher_id).html()+'">');		
		}

	function updateTeacher(teacher_id,event)
		{
			if(event.keyCode==13)//เมื่อกด Enter 
			{
				if($('#txtvalue'+teacher_id+'').val()=='')
				{
				event.preventDefault();
				alert('Please insert teachers firstname');
				}
				else if($('#txtvalue2'+teacher_id).val()=='')
				{
				event.preventDefault();
				alert('Please insert teachers lastname');
				}
				else if($('#txtvalue3'+teacher_id).val()=='')
				{
				event.preventDefault();
				alert('Please insert teachers ncu id');
				}
				else if($('#txtvalue4'+teacher_id).val()=='')
				{
				event.preventDefault();
				alert('Please insert teachers email');
				}
				else if($('#txtvalue6'+teacher_id).val()=='')
				{
				event.preventDefault();
				alert('Please insert teachers faculty');
				}
				else if($('#txtvalue'+teacher_id).val()==(event.keyCode==32))
				{
				event.preventDefault();
				alert('Please insert teachers firstname');
				}
				else if($('#txtvalue2'+teacher_id).val()==(event.keyCode==32))
				{
				event.preventDefault();
				alert('Please insert teachers lastname');
				}
				else if($('#txtvalue3'+teacher_id).val()==(event.keyCode==32))
				{
				event.preventDefault();
				alert('Please insert teachers ncu id');
				}
				else if($('#txtvalue4'+teacher_id).val()==(event.keyCode==32))
				{
				event.preventDefault();
				alert('Please insert teachers email');
				}
				else if($('#txtvalue6'+teacher_id).val()==(event.keyCode==32))
				{
				event.preventDefault();
				alert('Please insert teachers faculty');
				}
				else
				{
					$('#editimg'+teacher_id).show();
					$.post('function/update.php',
					{
						'teacher_firstname' : $('#txtvalue'+teacher_id).val(), 'teacher_lastname' : $('#txtvalue2'+teacher_id).val() , 'teacher_ncuid' : $('#txtvalue3'+teacher_id).val(),'teacher_email' : $('#txtvalue4'+teacher_id).val(), 'teacher_tel' : $('#txtvalue5'+teacher_id).val(), 'teacher_faculty' : $('#txtvalue6'+teacher_id).val() , 'teacher_id' : teacher_id
					},function(data)
					{
						$('#value'+teacher_id).html($('#txtvalue'+teacher_id).val());
						$('#value2'+teacher_id).html($('#txtvalue2'+teacher_id).val());
						$('#value3'+teacher_id).html($('#txtvalue3'+teacher_id).val());
						$('#value4'+teacher_id).html($('#txtvalue4'+teacher_id).val());
						$('#value5'+teacher_id).html($('#txtvalue5'+teacher_id).val());
						$('#value6'+teacher_id).html($('#txtvalue6'+teacher_id).val());
					});
				}
				mngSubject();
			}
		}

	function delStudent(student_id)
		{	
			if (confirm("Do you want to delete ?") )
			{
				$.post('function/delete.php',{'student_id': student_id} , function(data)//ใส่{'id':id} เข้าไปเพื่อรับ id จาก delete.php
				{
				showStudentProfile();
				});
			}

			else
			{
				showStudentProfile();
			}
		}

	function delTeacher(teacher_id)
		{	
			if (confirm("Do you want to delete ?") )
			{
				$.post('function/delete.php',{'teacher_id': teacher_id} , function(data)//ใส่{'id':id} เข้าไปเพื่อรับ id จาก delete.php
				{ 
				showTeacherProfile();
				});
			}

			else
			{
				showTeacherProfile();
			}
		}

//Manage Subject
	function showSubject()  
		{
			$.get('page/admin-login-addsubject.php',function(data)
				{
					getTchName(); 
					$('#adminInformation').html(data);
				});
		}

	function getTchName() 
		{
			$.getJSON('function/json-teacher.php',function(data) 
			{
				$('#subjectteacher').html('<option></option>');
				$.each(data,function(key, val) 
				{
					$('#subjectteacher').html(
					$('#subjectteacher').html()
					+ '<option id="'+val['teacher_id']+'">'+val['teacher_firstname']+' '+val['teacher_lastname']+'</option>'
					);
				});
			});
		}

	function addSubject()//เป็นปุ่มการทำงานของ submit
		{	
			if($('#subjectid').val()=='')
			{
				alert("Please insert Subject's ID");
			}
			else if($('#subjectname').val()=='')
			{
				alert("Please insert Subject's Name");
			}
			else if($('#subjectteacher').val()=='')
			{
				alert("Please insert Teacher's name to teach this subject");
			}	
			else{
			$.post('function/add-subject.php',{
				'subjectid' : $('#subjectid').val(),
				'subjectname' : $('#subjectname').val(),
				'subjectteacher' : $('#subjectteacher').val(),
				'subjectfaculty' : $('#subjectfaculty').val()},
				function(data)//ทำการรีบข้อมูลมาจาก response.php โดยทำการรับข้อมูลตามที่ได้กำหนดไว้
			{	
				alert("Add Subject Successful");});
				afterRegister();
				
			}
		}

	function showMngSubject()  
		{
			$.get('page/admin-login-mngsubject.php',function(data)
				{
					 mngSubject();
					$('#adminInformation').html(data);
				});
		}

	function mngSubject() 
		{
			$('#informationMain').html('Loading...');
				$.getJSON('function/json-subject.php',function(data)
			{
			$('#informationMain').html('');
			$.each(data,function(key,val){
			$('#informationMain').html(
			$('#informationMain').html()
			+'<table>'
			+'<div style="display:none">'+val['sub_id']+'</div>'
			+'<td width=150>'
			+'<font color="white" size=3>'
			+'<span id="value'+val['sub_id']+'">'+val['subject_id']+'</span>'
			+'</font></td>'
			+'<td width="330">'
			+'<font color="white" size=3>'
			+'<span id="value2'+val['sub_id']+'">'+val['subject_name']+'</span>'
			+'</font>'
			+'<td width=320>'
			+'<font color="white" size=3>'
			+'<span id="value3'+val['sub_id']+'">'+val['subject_teacher']+'</span>'
			+'</font>'
			+'</td><td width="130">'
			+'<font color="white" size=3>'
			+'<span id="value4'+val['sub_id']+'">'+val['subject_faculty']+'</span>'
			+'</font></td>'
			+'</td><td> <img id="editimg'+val['sub_id']+'" src="Picture-project/PNGfile/edit-icon.png" style="cursor:pointer;" onclick="editSubject('+val['sub_id']+');">'
			+'</td><td> <img id="delimg'+val['sub_id']+'" src="Picture-project/PNGfile/del-icon.png" style="cursor:pointer;" onclick="delSubject('+val['sub_id']+');">'
			+'</td></tr></table>'
			+'<img src="Picture-project/PNGfile/Text-line.png" width=1000>'
			);
			});
			});
		}

	function delSubject(sub_id)
		{	
			if (confirm("Do you want to delete ?") )
			{
				$.post('function/delete.php',{'sub_id': sub_id} , function(data)//ใส่{'id':id} เข้าไปเพื่อรับ id จาก delete.php
				{
					mngSubject();
				});
			}

			else
			{
				mngSubject();
			}
		}

	function editSubject(sub_id)
		{
			$('#editimg'+sub_id).hide();
			$('#value'+sub_id).html('<input id="txtvalue'+sub_id+'" type="text" maxlength="6"  onkeydown = "updateSubject('+sub_id+',event);" value="'+$('#value'+sub_id).html()+'">');
			$('#value2'+sub_id).html('<input id="txtvalue2'+sub_id+'" type="text" onkeypress="return isStringKey(event)" onkeydown = "updateSubject('+sub_id+',event);" value="'+$('#value2'+sub_id).html()+'">');
			$('#value3'+sub_id).html('<input id="txtvalue3'+sub_id+'" type="text" onkeypress="return isStringKey(event)" onkeydown = "updateSubject('+sub_id+',event);" value="'+$('#value3'+sub_id).html()+'">');
			$('#value4'+sub_id).html('<input id="txtvalue4'+sub_id+'" type="text" onkeypress="return isStringKey(event)" onkeydown = "updateSubject('+sub_id+',event);" value="'+$('#value4'+sub_id).html()+'">');		
		}

	function updateSubject(sub_id,event)
		{
			if(event.keyCode==13)//เมื่อกด Enter 
			{
				if($('#txtvalue'+sub_id+'').val()=='')
				{
				event.preventDefault();
				alert('Please insert subjects id');
				}
				else if($('#txtvalue2'+sub_id).val()=='')
				{
				event.preventDefault();
				alert('Please insert subjects name');
				}
				else if($('#txtvalue3'+sub_id).val()=='')
				{
				event.preventDefault();
				alert('Please insert teachers subject');
				}
				else if($('#txtvalue4'+sub_id).val()=='')
				{
				event.preventDefault();
				alert('Please insert facultys subject');
				}
				else if($('#txtvalue'+sub_id).val()==(event.keyCode==32))
				{
				event.preventDefault();
				alert('Please insert subjects id');
				}
				else if($('#txtvalue2'+sub_id).val()==(event.keyCode==32))
				{
				event.preventDefault();
				alert('Please insert subjects name');
				}
				else if($('#txtvalue3'+sub_id).val()==(event.keyCode==32))
				{
				event.preventDefault();
				alert('Please insert teachers subject');
				}
				else if($('#txtvalue4'+sub_id).val()==(event.keyCode==32))
				{
				event.preventDefault();
				alert('Please insert facultys subject');
				}
				else
				{
					$('#editimg'+sub_id).show();
					$.post('function/update.php',
					{
						'subject_id' : $('#txtvalue'+sub_id).val(), 'subject_name' : $('#txtvalue2'+sub_id).val() , 'subject_teacher' : $('#txtvalue3'+sub_id).val(),'subject_faculty' : $('#txtvalue4'+sub_id).val() , 'sub_id' : sub_id
					},function(data)
					{
						$('#value'+sub_id).html($('#txtvalue'+sub_id).val());
						$('#value2'+sub_id).html($('#txtvalue2'+sub_id).val());
						$('#value3'+sub_id).html($('#txtvalue3'+sub_id).val());
						$('#value4'+sub_id).html($('#txtvalue4'+sub_id).val());
					});
				}
				mngSubject();
			}
		}


function afterRegister()
	{
		$('#student_username').val('');
		$('#student_password').val('');
		$('#student_repassword').val('');
		$('#student_firstname').val('');
		$('#student_lastname').val('');
		$('#student_ncuid').val('');
		$('#student_year').val('');
		$('#student_email').val('');
		$('#student_tel').val('');

		$('#teacher_username').val('');
		$('#teacher_password').val('');
		$('#teacher_repassword').val('');
		$('#teacher_firstname').val('');
		$('#teacher_lastname').val('');
		$('#teacher_ncuid').val('');
		$('#teacher_email').val('');
		$('#teacher_tel').val('')

		$('#subjectid').val('');
		$('#subjectname').val('');
		$('#subjectteacher').val('');

		$('#forgotusername').val('');
		$('#forgotfirstname').val('');
		$('#forgotncuid').val('');
		$('#forgotemail').val('');

		$('#title').val('');
		$('#startDate').val('');
		$('#endDate').val('');
		$('#subject').val('');
		$('#detail').val('');
	}
function isNumberKey(evt)
       {
          var charCode = (evt.which) ? evt.which : event.keyCode;
          if (charCode < 48 || charCode > 57)
		   {
				   event.preventDefault();
			alert ("Please insert number");
		   }
		
             return true;
       }

	    function isStringKey(evt)
       {
          var charCode = (evt.which) ? evt.which : event.keyCode;
          if (charCode < 33 || charCode > 64
			&&(charCode < 91 || charCode > 96)
			&&(charCode < 123 || charCode > 126))
		   {
				return true;	
		   }
			else
		   {
				event.preventDefault();
				alert ("Can not be number");
		   }  
       }